﻿// Example header text. Can be configured in the options.
using System;
using System.Data;
using System.Linq;
using vtech_frameWorks.DAO;
using vtech_frameWorks.Exceptions;
using vtech_frameWorks.Object;

namespace vtech_system.GroupUser
{
    class ClsGroupUserBS : ClsObjectBS
    {
        public override void DoDelete(System.Data.DataRow drow)
        {
            ClsGroupUserDAO obj = new ClsGroupUserDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();
                obj.Delete(drow);
                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        public override void DoEdit(System.Data.DataTable dt)
        {
            ClsGroupUserDAO obj = new ClsGroupUserDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();
                foreach (DataRow drow in dt.Rows)
                {
                    obj.Edit(drow);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        public override void DoInsert(System.Data.DataTable dt)
        {
            ClsGroupUserDAO obj = new ClsGroupUserDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();
                foreach (DataRow drow in dt.Rows)
                {
                    obj.Insert(drow);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        public override System.Data.DataTable GetAll()
        {
            ClsGroupUserDAO obj = new ClsGroupUserDAO();
            using (DsGroupUser dsGroupUser = new DsGroupUser())
            {
                dsGroupUser.DtGroupUser.Merge(obj.GetAll());
                dtObject = dsGroupUser.DtGroupUser;
                return dsGroupUser.DtGroupUser;
            }
        }
    }
}